/**
 *   
 * 
 * Project: workflow-platform
 * 
 * DemoController.java File Created at 上午10:04:39
 * 
 */
package com.stardigi.workflowplatform.controller;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@RestController
public class DemoController {
	@Autowired
	private ProcessEngine processEngine;
	
	@Autowired
	private RuntimeService runtimeService;
	
	@Autowired
	private HistoryService historyService;
	
	
	@Autowired
	private TaskService taskService;
	
	@RequestMapping("/startDemoProcess")
	public String start() {
		String id="12321313131";
		Authentication.setAuthenticatedUserId(id);
		ProcessInstance instance=runtimeService.startProcessInstanceByKey("demoProcess", UUID.randomUUID().toString());

		return instance.getBusinessKey();
	}
	
	@RequestMapping("/completeTask")
	public void completeTask(HttpServletRequest request) {
		String bizKey=request.getParameter("bizKey");
		Task task=taskService.createTaskQuery().processInstanceBusinessKey(bizKey).list().get(0);

		taskService.complete(task.getId());
		
	}

}

